﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2024/5/27
 * 时间: 1:38
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Net;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing;
using System.Windows.Forms;

namespace form
{
	/// <summary>
	/// Description of Form1.
	/// </summary>
	public partial class Form2 : Form
	{
		public Form2()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			  WebClient webClient = new WebClient();
			ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.SystemDefault | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
			  Byte[] imgData = webClient.DownloadData("https://api.jun.la/60s.php?format=image");
			  Stream ms = new MemoryStream(imgData);
			  ms.Position = 0;
			  Image img = Image.FromStream(ms);
			 // img.Save(@"60s.jpg", ImageFormat.Jpeg);
			  Image resizedImage = resizeImage(img, new Size(img.Width/2, img.Height/2));
			pictureBox1.Image=resizedImage ;
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		public static Image resizeImage(Image imgToResize, Size size) {   //https://www.delftstack.com/zh/howto/csharp/resize-an-image-in-csharp/
	      return (Image)(new Bitmap(imgToResize, size));
	    }
	}
}
